package com.ludomancy.starwave;

import java.awt.Graphics;

import com.ludomancy.gamelib.PositionInterpolator;

public class PortalAnimation implements Animation
{
	private PortalShip portal;
	private PortalShip twin;
	private Ship jumper;
	private PositionInterpolator interpolator;
	

	public PortalAnimation(PortalShip ship, PortalShip twin, Ship jumper)
	{
		this.portal = ship;
		this.twin = twin;
		this.jumper = jumper;

		int pixelX = ship.px*Settings.TILE_SIZE;
		int pixelY = ship.py*Settings.TILE_SIZE;
		int targetPixelX = twin.px*Settings.TILE_SIZE;
		int targetPixelY = twin.py*Settings.TILE_SIZE;
		
		interpolator = new PositionInterpolator(pixelX, pixelY, targetPixelX, targetPixelY, Settings.PORTAL_TELEPORT_STEPS);
		start();
	}
	
	public void start()
	{
	}
	
	public void update()
	{
		interpolator.update();
	}
	
	public boolean isOver()
	{
		return interpolator.isMoving() == false;
	}
	
	public void paint(Graphics g)
	{
		// source portal
		int x = portal.px * Settings.TILE_SIZE;
		int y = portal.py * Settings.TILE_SIZE;
		portal.paintInYard(g, x, y);
		
		// destination portal
		x = twin.px * Settings.TILE_SIZE;
		y = twin.py * Settings.TILE_SIZE;
		portal.paintInYard(g, x, y);

		// teleporting ship
		jumper.paint(g, interpolator.x, interpolator.y);
	}
}
